home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue28 / mtsearch / MTSEARCH.ZIP / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-10-13  |  3.2 KB  |  110 lines

  1. {+--------------------------------------------------------------------------+
  2.  | Created:     10.97
  3.  | Author:      Martin Waldenburg
  4.  | Copyright    1997, all rights reserved.
  5.  | Description: Demo for mwTSearch.
  6.  | It's provided as is, without a warranty of any kind.
  7.  | You use it at your own risc.
  8.  | E-Mail me at Martin.Waldenburg@t-online.de
  9.  +--------------------------------------------------------------------------+}
  10. unit Unit1;
  11.  
  12. interface
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, mwTSearch,
  16.   StdCtrls, mwFastTime;
  17.  
  18. type
  19.   TForm1 = class(TForm)
  20.     Button1: TButton;
  21.     Time1: TmwFastTime;
  22.     Edit1: TEdit;
  23.     Edit2: TEdit;
  24.     Edit3: TEdit;
  25.     Button2: TButton;
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure Button2Click(Sender: TObject);
  28.   private
  29.     function RndString:String;
  30.   public
  31.     { Public-Deklarationen }
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.DFM}
  40.  
  41. function TForm1.RndString:String;
  42. var
  43.   J, Len: integer;
  44.   aChar: Char;
  45.   CharArray: array[0..5] of Char;
  46. begin
  47.   Randomize;
  48.   Len:= random(5);
  49.   for J := 0 to Len -1 do
  50.     begin
  51.       repeat
  52.       aChar := Chr(random(58) + Ord('A'));
  53.       until (aChar <= 'Z') or (aChar >= 'a');
  54.       CharArray[J]:= aChar;
  55.     end;
  56.     CharArray[Len]:= #0;
  57.     Result:= CharArray;
  58. end;
  59.  
  60. procedure TForm1.Button1Click(Sender: TObject);
  61. var
  62.   Search: TTISearch;
  63.   TextLine: String;
  64.   I: Integer;
  65. begin
  66.   TextLine:= 'TTSearch  (TurboSearch) is a very fast search engine, ' +
  67.              'about twice as fast as Boyer-Moore, '+
  68.              'based on an article in the German magazine c`t (8/97).' +
  69.              'However "Look_at" isn`t implemented, because I can`t see any sense in Pascal.'+
  70.              'The original is in "C". You can search case sensitive or case insensitive.' + #13#10;
  71.   for I:= 1 to 12 do TextLine:= TextLine + RndString + #13#10 + TextLine;
  72.   Time1.Start;
  73.   Search:= TTISearch.Create;
  74.   Search.Init('isn`t implemented,');
  75.   Search.FindFirst(TextLine);
  76.   while not Search.Finished do Search.Next;
  77.   Time1.Stop;
  78.   Edit1.Text:= 'String Size: ' + IntToStr(Length(TextLine));
  79.   Edit2.Text:= 'Found ' + IntToStr(Search.Count);
  80.   Search.Free;
  81.   Edit3.Text:= Time1.ElapsedTime;
  82. end;
  83.  
  84. procedure TForm1.Button2Click(Sender: TObject);
  85. var
  86.   Search: TTISearch;
  87.   TextLine: String;
  88.   I: Integer;
  89. begin
  90.   TextLine:= 'TTSearch  (TurboSearch) is a very fast search engine, ' +
  91.              'about twice as fast as Boyer-Moore, '+
  92.              'based on an article in the German magazine c`t (8/97).' +
  93.              'However "Look_at" isn`t implemented, because I can`t see any sense in Pascal.'+
  94.              'The original is in "C". You can search case sensitive or case insensitive.' + #13#10;
  95.  for I:= 1 to 12 do TextLine:= TextLine + RndString + #13#10 + TextLine;
  96.   Time1.Start;
  97.   Search:= TTISearch.Create;
  98.   Search.IInit('isN`t imPlemenTed,');
  99.   Search.IFindFirst(TextLine);
  100.   while not Search.Finished do Search.INext;
  101.   Time1.Stop;
  102.   Edit1.Text:= 'String Size: ' + IntToStr(Length(TextLine));
  103.   Edit2.Text:= 'Found ' + IntToStr(Search.Count);
  104.   Search.Free;
  105.   Edit3.Text:= Time1.ElapsedTime;
  106.  
  107. end;
  108.  
  109. end.
  110.